﻿var categoryURL = '/api/categoryApi';
jQuery.support.cors = true;

$(document).ready(function () {
    /*Event Binding*/
    /*From Masteg page*/
    $('#CategoryMenu').on('click', function () { ListAllCategories(); });
});

function ListAllCategories() {
    $('#Content').fadeIn(1000);
    $.getJSON(categoryURL, function (categories) {
        $('#Content').html('');
        $('<Table id="Grid" ><tr class="header"><th>CategoryName</th><th colspan="2"></th></tr></Table>').appendTo('#Content');
        if (categories.length > 0) {
            $.each(categories, function (i, cat) {
                $('<tr CatId=' + cat.CategoryId + '><td class="EditCategory"><a href="#">' + cat.CategoryName + '</a></td>' +
                  '<td><a href="#" class="EditCategory">Edit</a></td>' +
                  '</td><td><a href="#" class="DeleteCategory">Delete</a>' +
                  '</tr>').appendTo('#Grid').fadeIn();
            });
        }
        //$('<tr ProdId=0><td></td><td colspan="2"><input type="button" value="Add Product" onclick="EditProduct(this)"  /></td></tr>').appendTo('#Grid');
    }).fail(function (jqxhr, textStatus, error) {
        alert(error);
    });
}

function EditCategory(obj) {

}

function DeleteCategory(obj) {
}